/**
 * Created by guobaogang on 2018/9/13.
 */
import React, {Component} from 'react';
import {Panel, Button} from 'tinper-bee';
import ReactDOM from 'react-dom';
import {high, createPage, base, getUrlParam, toast, promptBox} from 'nc-lightapp-front';
import {hrAjax as ajax } from 'src/hrpub/common/utils/utils';
import handdleCheckedData from '../../../public/functions/checkDataPermissionAction';
import './index.less';
import Header from "./components/Header";
import MainTable from "./components/MainTable";
import EditForm from "./components/EditForm";
import FileUpload from "./components/FileUpload";
import AddNew from "./components/AddNew";
import getOneAgreementInfo from "./container/functions/getOneAgreementInfo"
import updateButtonStatus from "./container/functions/updateButtonStatus";
import getMainTableData from "./container/functions/getMainTableData";
import deleteAgreementData from "./container/functions/deleteAgreementData";
import effectiveAgreementData from './container/functions/effectiveAgreementData';
import saveAgreementData from "./container/functions/saveAgreementData";
import getAgreementTypeData from "./container/functions/getAgreementType";
import { handleHash } from 'src/hrpub/common/utils/utils';
import WpsModal from 'src/hrpub/common/components/wpsPreModel';

const appcode = "60110507", pagecode = "60110507p", tableId = 'list', format = "YYYY-MM-DD";

// const reqData = [
// 	{
// 		rqUrl: '/platform/templet/querypage.do',
// 		rqJson: `{\n  \"pagecode\": \"60110501p\",\n  \"appcode\": \"60110501\"\n}`,
// 		rqCode: 'searchQuery'
//     },
//     {
// 		rqUrl: '/platform/templet/querypage.do',
// 		rqJson: `{\n  \"pagecode\": \"${pagecode}\",\n  \"appcode\": \"${appcode}\"\n}`,
// 		rqCode: 'template'
// 	},
// 	{
// 		rqUrl: '/platform/appregister/queryallbtns.do',
// 		rqJson: `{\n  \"pagecode\": \"${pagecode}\",\n  \"appcode\": \"${appcode}\"\n}`,
// 		rqCode: 'button'
// 	},
// 	{
// 		rqUrl: '/platform/appregister/queryappcontext.do',
// 		rqJson: `{\n  \"appcode\": \"${appcode}\"}`,
// 		rqCode: 'context'
// 	}
// ];

class ProChange extends Component {
    constructor(props) {
        super(props);
        this.registed = ['nullCard', 'postcontCard', 'secrerycontCard', 'traincontCard', 'postcontCard_add', 'secrerycontCard_add', 'traincontCard_add',
        'postcont', 'secrerycont', 'traincont', 'releasecontlist', 'psnList', 'chgPsnList']
        if (props.use) {
            props.use.form('nullCard', 'postcontCard', 'secrerycontCard', 'traincontCard', 'postcontCard_add', 'secrerycontCard_add', 'traincontCard_add')
            props.use.editTable('postcont', 'secrerycont', 'traincont', 'releasecontlist', 'psnList', 'chgPsnList')
            props.use.search('listquery')
        }
        this.config = {
            pagecode: pagecode,
            appcode: appcode
        };
        this.state = {
            orgVal: {}, // 存储组织
            json: {},
            dataList: [], // 存储所有协议类型，用于下拉选择框
            agreementType: null, // 协议类型 20190711 默认从协议类型接口中获取第一个数据
            isEdit: false, // 判断是不是编辑状态
            pageFlag: "list", // 判断页面展示 list:列表 card：卡片
            deleteData: [],
            deleteIndex: [],
            effectiveIndex: [], // 生效数据下标用于去除
            effectiveData: [], // 生效数据
            editPk: '', // 修改使用主键查询
            isRefer: false,
            index: '', // 协议类型多语
            pageInfo: { // 分页信息
                pageIndex: 1,
                pageSize: "10",
                total: "0",
                totalPage: ""
            },
            nodeRefs: {wpsview: null}
        };

        // snCreateUIDom({}, reqData, (data) => {
        //     let queryTemplate = data.searchQuery;
        //     let oid = queryTemplate.listquery && queryTemplate.listquery.oid;
        //     let postcont = data.template.postcont.items;
        //     let secrerycont = data.template.secrerycont.items;
        //     let traincont = data.template.traincont.items;
        //     this.initMeta(postcont,this);
        //     this.initMeta(secrerycont,this);
        //     this.initMeta(traincont,this);
        //     this.setTemplateData(data);
        //     this.setState({
        //         buttons: data.button || [],
        //         context: data.context || {},
        //         oid: oid
        //     });
        //     props.MultiInit.getMultiLang({
        //         moduleId: 'cm6011',
        //         domainName: 'hrcm',
        //         callback: (json, status, inlt) => {
        //             if (status) {
        //                 this.setState({json, inlt}); //存json和inlt到页面state中并刷新页面
        //             }
        //         }
        //     });
        //     props.meta.setMeta(data && data.template ? data.template : {});
        //     props.meta.addMeta(queryTemplate);
        //     props.button.setButtons(data && data.button ? data.button : {});
        // });
        
        props.createUIDom(this.config, (data) => {
            let oid = data.template.listquery && data.template.listquery.oid;
            let postcont = data.template.postcont.items;
            let secrerycont = data.template.secrerycont.items;
            let traincont = data.template.traincont.items;
            
            this.setState({
                buttons: data.button || [],
                context: data.context || {},
                oid: oid
            });
            props.MultiInit.getMultiLang({
                moduleId: 'cm6011',
                domainName: 'hrcm',
                callback: (json, status, inlt) => {
                    if (status) {
                        this.setState({json, inlt},()=>{
                            this.initMeta(postcont,this);
                            this.initMeta(secrerycont,this);
                            this.initMeta(traincont,this);
                            this.setTemplateData(data);
                        }); //存json和inlt到页面state中并刷新页面
                    }
                }
            });
            let temp = data.template;
            for (let key in temp) {
                if(temp.hasOwnProperty(key) && temp[key].moduletype){
                    if(!this.registed.includes(temp[key].code)) {
                        temp[key].moduletype === 'form' && props.use.form(temp[key].code);
                        temp[key].moduletype === 'table' && props.use.editTable(temp[key].code);
                        this.registed.push(temp[key].code);
                    }
            　　}
            }
            props.meta.setMeta(data && data.template ? data.template : {});
            props.button.setButtons(data && data.button ? data.button : {});
        });
        this.updateOrgValue = this.updateOrgValue.bind(this);
        this.updateAgreeType = this.updateAgreeType.bind(this);
        this.updateState = this.updateState.bind(this);
        this.updateButtonStatus = this.updateButtonStatus.bind(this);
        this.deleteAgreementData = this.deleteAgreementData.bind(this);
        this.effectiveAgreementData = this.effectiveAgreementData.bind(this);
        this.onRowDoubleClick = this.onRowDoubleClick.bind(this);
        this.setPageShow = this.setPageShow.bind(this);
    }

    async componentWillMount() {
        await getAgreementTypeData.call(this);
        updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType, this.state.isEdit);
        
    }

    componentDidMount() {
        if (window.location.href.match('localhost:3006'))
            window.location.hash = '?page=201908171119'
        window.hh = this
    }

    //列表分页
    paginationEve(key) {
        let { pageInfo } = this.state;
        pageInfo.pageIndex = key;
        this.setState({
            pageInfo
        },()=>{
            // getMainTableData.call(this);
            let getConditions = this.props.search.getQueryInfo('listquery',true);
            let conditions = getConditions;
            getMainTableData.call(this,conditions);
        })
    }

    //选择每页显示的条数
    pageSizeSelect(pageSize) {
        let { pageInfo } = this.state;
        pageInfo.pageSize = pageSize;
        this.setState({
            pageInfo
        },()=>{
            // getMainTableData.call(this);
            let getConditions = this.props.search.getQueryInfo('listquery',true);
            let conditions = getConditions;
            getMainTableData.call(this,conditions);
        })
    }

    //协议文本
    contractText(obj) {
        this.textButtonClick(obj);
    }

    // 协议文本操作
    textButtonClick (obj) {
        let pk_agreement = ''
        if (this.state.pageFlag === 'list') {
            if (obj && obj.values && obj.values.pk_agreement) {
                pk_agreement = obj.values.pk_agreement.value;
            }else {
                toast({
                    color: 'warning',
                    content: this.state.json['cm6011-000106']//* 国际化处理： 请选择要操作的协议*/
                });
                return;
            }
        } else {
            pk_agreement = this.state.editPk;
        }
        let paramObj = {
            pk_org: this.state.orgVal.refpk,
            pk_agreement: pk_agreement
        }
        ajax({
            url: '/nccloud/hrcm/templet/AgreementTextViewAction.do',
            data: paramObj,
            success: (result) => {
                if (result.success) {
                    if (this.state.pageFlag === 'list') {
                        this.state.nodeRefs.wpsview.openView([{data: obj}], 'ag')
                    } else {
                        let formData = this.props.form.getAllFormValue(this.state.agreementType + "Card").rows;
                        this.state.nodeRefs.wpsview.openView(formData, 'ag')
                    }
                    // let origin = 'uclient://start/' + window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '')
                    // window.location.href = origin + result.data
                }
            }
        })
    }

    //保存按钮点击事件
    saveButtonClick() {
        const agreementData = this.props.form.getAllFormValue(this.state.agreementType + 'Card', true);
        if(!this.props.form.isCheckNow(this.state.agreementType + 'Card')){
            return false;
        }
        if (!agreementData.rows[0].values.signdate.value){
            toast({
                color: 'danger',
                content:this.state.json['cm6011-000112']//* 国际化处理： 下列字段值不能为空：[业务发生日期]*/
            });
            return;
        }
        saveAgreementData.call(this,
            () =>{
                this.promptBoxModal();
            }
        );
    }

    promptBoxModal(){
        promptBox({
            color: 'info',
            title: this.state.json['cm6011-000071']/*国际化处理：生效*/,
            content: this.state.json['cm6011-000048']/*国际化处理：是否立即生效？*/,
            beSureBtnName: this.state.json['cm6011-000057']/*国际化处理：是*/,
            cancelBtnName: this.state.json['cm6011-000058']/*国际化处理：否*/,
            beSureBtnClick: () => {
                this.setState({
                    effectivePks: this.state.editPk,
                }, () => {
                    effectiveAgreementData.call(this)
                    this.refs.editForm.setMainFormEdit('browse')
                })
            },
            cancelBtnClick: () => {
                this.refs.editForm.setMainFormEdit('browse')
            }
        })
    }

    // 新增按钮事件
    addButtonClick () {
        this.refs.addNew.setNewIncreasedDis(true)
    }

    //删除按钮事件(批量删除不传deleteData)
    deleteButtonClick(v) {
        // let deletePks='';
        // let { agreementType, customAgreement } = this.state;
        // if(this.state.pageFlag === 'card'){ //卡片界面
        //     deletePks = this.state.editPk;
        // }else if(this.state.pageFlag === 'list'){ //列表界面
        //     let data = deleteData ? deleteData : this.props.editTable.getCheckedRows(customAgreement ? customAgreement : agreementType);
        //     deletePks = this.getAgreementPksString(data);
        // }else {
        //     return;
        // }

        let { agreementType, json, customAgreement } = this.state;
        let pks = [];
        if( !!v ){
            pks.push(v && v.values.pk_agreement.value);
        }else{
            pks = this.getAgreementPksString();
        }

        if(!!pks.length){
            handdleCheckedData(pks, 'delete', 'agreement', ()=>{
                promptBox({
                    color: 'warning',
                    title: this.state.json['cm6011-000041']/*国际化处理：确认删除*/,
                    content: this.state.json['cm6011-000042']/*国际化处理：您确定要删除选择数据吗？*/,
                    hasCloseBtn:true, // 是否有关闭
                    beSureBtnClick: () => {
                        this.setState({
                            deletePks: pks,
                        }, () => {
                            deleteAgreementData.call(this)
                        })
                    },
                });
            });
        }else {
            toast({
                color:'warning',
                content: this.state.json['cm6011-000039']/*国际化处理：请选择要删除的条目!*/
            })
        }
    }

    /**
     * 获取一个或多个主键的字符串
     * @param data
     * @returns {string} 主键之间用，分割
     */
    getAgreementPksString(deleteData){
        let pk_agreements = [];
        let { agreementType, customAgreement , editPk} = this.state;
        if (this.state.pageFlag === 'card') { //卡片界面
            pk_agreements.push(editPk);
        } else if (this.state.pageFlag === 'list') { //列表界面
            let data = deleteData ? deleteData : this.props.editTable.getCheckedRows(customAgreement ? customAgreement : agreementType);
            if (data instanceof Array) {
                for (const index in data) {
                    pk_agreements.push(data[index].data.values.pk_agreement.value);
                }
            } else {
                pk_agreements.push(data.values.pk_agreement.value);
            }
        } else {
            return;
        }
        
        return pk_agreements;

        // let pk_agreements ="";
        // if(data instanceof Array){
        //     for(const index in data){
        //         if(pk_agreements && pk_agreements !==""){
        //             pk_agreements = pk_agreements+","+data[index].data.values.pk_agreement.value;
        //         }else{
        //             pk_agreements = data[index].data.values.pk_agreement.value;
        //         }
        //     }
        // }else {
        //     pk_agreements = data.values.pk_agreement.value;
        // }
        // return pk_agreements;
    }

    // 点击生效事件
    isTakeEffectEvent(){
        let { json } = this.state;
        let pks = this.getAgreementPksString();
        if (!!pks.length) {
            handdleCheckedData(pks, 'effect', 'agreement', ()=>{
                this.effectiveButtonClick(pks);
            });
        }else{
            toast({color: 'warning', content: json['cm6011-000135']})
        }
        
    }

    //生效按钮事件
    effectiveButtonClick(effectivePks) {
        // let effectivePks='';
        // let { agreementType, customAgreement } = this.state;
        // if(this.state.pageFlag === 'card'){ //卡片界面
        //     effectivePks = this.state.editPk;
        // }else if(this.state.pageFlag === 'list') { //列表界面
        //     let effectData = this.props.editTable.getCheckedRows(customAgreement ? customAgreement : agreementType);
        //     effectivePks = this.getAgreementPksString(effectData);
        // }else {
        //     return;
        // }
        promptBox({
            color: 'warning',
            title: this.state.json['cm6011-000071']/*国际化处理：生效*/,
            content: this.state.json['cm6011-000048']/*国际化处理：是否立即生效？*/,
            beSureBtnName: this.state.json['cm6011-000057']/*国际化处理：是*/,
            cancelBtnName: this.state.json['cm6011-000058']/*国际化处理：否*/,
            beSureBtnClick: () => {
                this.setState({
                    effectivePks: effectivePks,
                }, () => {
                    effectiveAgreementData.call(this)
                })
            }
        });
    }

    //取消按钮事件
    cancelButtonClick(btncode){
        promptBox({
            color: 'warning',
            title: this.state.json['cm6011-000000']/*国际化处理：确认取消*/,
            content: this.state.json['cm6011-000001']/*国际化处理：是否确认要取消*/,
            beSureBtnName: this.state.json['cm6011-000057']/*国际化处理：是*/,
            cancelBtnName: this.state.json['cm6011-000058']/*国际化处理：否*/,
            beSureBtnClick: () => {
                this.props.editTable.cancelEdit(this.state.agreementType + 'Card');
                this.updateState({
                    btncode: btncode,
                    pageFlag: 'card',
                    isEdit: false
                });
                this.refs.editForm.setMainFormEdit('browse')
            }
        });
    }

    //刷新按钮事件
    refreshButtonClick(){
        if(this.state.pageFlag === 'list'){
            this.getMainTableData.call(this,
                toast({
                    color: 'success',
                    content: this.state.json['cm6011-000006']/* 国际化处理： 刷新成功*/
                })
            );
        }else if(this.state.pageFlag === 'card'){
            getOneAgreementInfo.call(this,
                toast({
                    color: 'success',
                    content: this.state.json['cm6011-000006']/* 国际化处理： 刷新成功*/
                })
            );
        }else {
            return;
        }
    }

     //添加附件校验事件
     flieCheckedData(rowRecord){
        let pk_agreement = '';
        if (this.state.pageFlag === 'list') {
            pk_agreement = rowRecord.values.pk_agreement.value;
        } else {
            pk_agreement = this.state.record.values.pk_agreement.value;
        }
        handdleCheckedData(pk_agreement, 'attachment', 'agreement', ()=>{
            this.fileButtonClick(pk_agreement);
        });
    }

    //附件管理按钮事件
    fileButtonClick(pk_agreement){
        // let pk_psndoc_sub = '';
        // if (this.state.pageFlag === 'list') {
        //     pk_psndoc_sub = rowRecord.values.pk_psndoc.value;
        // } else {
        //     pk_psndoc_sub = this.state.record.values.pk_psndoc.value;
        // }
        this.refs.FileUpload.showUploader(pk_agreement);
    }

    // //列表附件管理
    // flieViewShow(record) {
    //     this.fileButtonClick(record);
    // }

    //设置模板信息
    setTemplateData(data){
        let listIdArr = new Set();
        let template = data && data.template;
        for( let name in template){
            if(name.indexOf('List') >= 0){
                listIdArr.add(name)
            }
        }
        listIdArr = Array.from(listIdArr);
        // console.log(listIdArr);
        listIdArr.forEach((v,i)=>{
            let dataItems = data.template[v].items;
            this.initMeta(dataItems,this);
        });
    }
    
    initMeta(data,opt){
        let json = this.state.json;
        data.forEach((item, key) => {  //添加协议编号超链接
            if (item.attrcode === 'contcode') {
                item.renderStatus = 'browse'
                item.render = (text, record, index) => {
                    return (
                        <span style={{color: '#0073E1', cursor: 'pointer'}}
                              onClick={this.onRowDoubleClick.bind(this,record,index)}>
                                {record && record.values['contcode'] && record.values['contcode'].value}
                        </span>
                    );
                };
            }
        });
        //添加附件
        data.push({
            attrcode: 'attachment',
            itemtype: 'customer',
            hyperlinkflag: false,
            label: json['cm6011-000062'], /* 国际化处理： 附件管理*/
            width: '110px',
            textAlign: 'center',
            visible: true,
            fixed: 'right',
            render(text, record, index) {
                let billId = record.values.pk_agreement.value;
                let billNo = record.values.agreementcode.value
                return (
                    <span className="icon-file-icon-fujianshenpi">
                        <i className="icon iconfont icon-fujianshenpi" onClick={
                            opt.flieCheckedData.bind(opt,record)
                        }>&nbsp;</i>
                    </span>
                )
            }
        });
        data.push({
            attrcode: 'handleArea',
            itemtype: 'customer',
            hyperlinkflag: false,
            label: json['cm6011-000064'], /* 国际化处理： 操作*/
            width: '250px',
            textAlign: 'center',
            visible: true,
            fixed: 'right',
            render(text, record, index) {
                return (
                    <div>
                        <span style={{color: '#0073E1', cursor: 'pointer',marginRight: '12px'}}
                              onClick={opt.modifyListData.bind(opt,record)}
                        >
                            {opt.state.json['cm6011-000067']/* 国际化处理： 修改*/}
                        </span>
                        <span style={{color: '#0073E1', cursor: 'pointer',marginRight: '12px'}}
                              onClick={opt.deleteButtonClick.bind(opt,record)}
                        >
                            {opt.state.json['cm6011-000065']/* 国际化处理： 删除*/}
                        </span>
                        <span style={{color: '#0073E1', cursor: 'pointer'}}
                              onClick={opt.contractText.bind(opt,record)}
                        >
                            {opt.state.json['cm6011-000113']/* 国际化处理： 协议文本*/}
                        </span>
                    </div>
                )
            }
        });
    }

    //更新组织
    updateOrgValue(value) {
        this.setState({
            orgVal: value
        }, () => {
            if (!value.refpk) {
                this.props.editTable.setTableData(this.agreementType, {rows: []}, false);
                updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType);
            } else {
                this.getMainTableData();
            }
        })
    }

    //更新按钮状态
    updateButtonStatus() {
        updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType);
    }

    //更新协议类型
    updateAgreeType(value) {
        let customAgreement; //如果是自定义模板则添加List
        if(value && value.indexOf('hrcm_agreement') === 0){
            customAgreement = value + 'List';
            this.setState({
                customAgreement: customAgreement
            })
        }else{
            this.setState({
                customAgreement: customAgreement
            })
        }
        this.setState({
            agreementType: value
        }, () => {
            if (!value) {
                this.props.editTable.setTableData(value, {rows: []}, false);
                updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType);
            } else {
                this.getMainTableData();
            }
        })

    }

    //更新table状态 obj={
    // btncode: btncode, //触发事件
    // pageFlag: 'card', //显示页面
    // isEdit: true, // 是否编辑状态
    // pk_agreement: selectData.record.values.pk_agreement.value 数据主键
    // }
    updateState(obj) {
        this.props.editTable.setStatus(this.state.agreementType + 'Card', 'edit');
        if (obj.btncode === 'cancel' || obj.btncode === "detail") {
            this.props.editTable.setStatus(this.state.agreementType + 'Card', 'browse');
        }
        this.setState({
            pageFlag: obj.pageFlag, //页面状态
            isEdit: obj.isEdit,
        },() => {
            updateButtonStatus.call(this, this.state.orgVal, this.state.agreementType, obj.isEdit)
            if(this.state.pageFlag === 'list'){
                this.getMainTableData();
            }
        });
        if (obj.btncode === "add") {
            // console.log("add")
        } else if (obj.btncode === "edit" || obj.btncode === "detail") {
            getOneAgreementInfo.call(this)
        }
    }

    //删除单据
    deleteAgreementData(value) {
        this.setState({
            deleteData: value,
        }, () => {
            deleteAgreementData.call(this)
        })

    }

    //生效单据
    effectiveAgreementData(value) {
        this.setState({
            effectiveData: value,
        }, () => {
            effectiveAgreementData.call(this)
        })

    }

    //查询单据数据
    getMainTableData() {
        getMainTableData.call(this);
    }

    //表单双击事件
    onRowDoubleClick(record) {
        this.setState({
            editPk: record.values.pk_agreement.value,
            record
        },()=>{
            this.updateState({
                btncode: 'detail', //触发事件
                pageFlag: 'card', //显示页面
                isEdit: false, // 是否编辑状态
                pk_agreement: record.values.pk_agreement.value //数据主键
            })
        })

    }

    //修改列表数据
    modifyListData(obj) {
        let pk_agreement = obj.values.pk_agreement.value;
        this.setState({
            editPk: pk_agreement
        },()=>{
            handdleCheckedData(pk_agreement, 'edit', 'agreement', ()=>{
                this.updateState({
                    btncode: 'edit',
                    pageFlag: 'card',
                    isEdit: true
                })
                this.refs.editForm.setMainFormEdit('edit')
            });
        })
    }

    //删除列表数据
    // isDeleteRowData(obj) {
    //     this.deleteButtonClick(obj);
    // }

    //操作卡片翻页
    handleCardPagination(pk){
        this.setState({
            editPk: pk
        },()=>{
            getOneAgreementInfo.call(this)
        })
    }

    //修改按钮点击事件
    editButtonClick(btncode) {
        let agreementType = this.state.agreementType;
        if(agreementType !== 'postcont' &&  agreementType !== 'secrerycont' && agreementType !== 'traincont'){
            agreementType = agreementType + 'List';
        }
        const selectData = this.props.editTable.getClickRowIndex(agreementType);
        if (!(selectData && selectData.record && selectData.record.values)) {
            toast({
                color:'warning',
                content: this.state.json['cm6011-000106']//* 国际化处理： 请选择要操作的协议*/
            })
            return;
        }
        let pk_agreement = selectData.record.values.pk_agreement.value;
        handdleCheckedData(pk_agreement, 'edit', 'agreement', ()=>{
            this.updateState({
                btncode: btncode,
                pageFlag: 'card',
                isEdit: true,
                pk_agreement: pk_agreement
            })
            this.refs.editForm.setMainFormEdit('edit')
        });
    }

    // 设置主表单编辑态
    setMainFormEdit () {
        this.refs.editForm.setMainFormEdit()
    }

    //打开查询
    listQuery () {
        let { orgVal } = this.state;
        this.props.search.openAdvSearch('listquery', true, ()=>{
            let meta = this.props.meta.getMeta();
            let items = meta.listquery.items;
            items.length > 0 && items.map((item,index)=>{
                if(item.attrcode === 'pk_psnjob.pk_dept'){
                    item.queryCondition = {
                        pk_hrorg: orgVal.refpk
                    }
                }
            })
            this.props.meta.setMeta(meta);
        });
    }
    // 查询数据
    searchData = () => {
        // let conditions = props.search.getAllSearchData('query').conditions || [];
        let getConditions = this.props.search.getQueryInfo('listquery',true);
        let conditions = getConditions;
        getMainTableData.call(this,conditions);
    }

    //设置分页显示隐藏
    setPageShow = (isVisiblePagination,pageInfo)=>{
        this.setState({
            isVisiblePagination,
            pageInfo
        })
    }

    /**
     * 按钮点击事件
     * @param btncode 按钮类型
     */
    onBtnClickOperation(btncode){
        switch (btncode) {
            case 'add':
                this.addButtonClick()
                break;
            case 'edit':
                this.editButtonClick(btncode)
                break;
            case 'delete':
                this.deleteButtonClick()
                break;
            case 'save':
                this.saveButtonClick()
                break;
            case 'effect':
                this.isTakeEffectEvent()
                break;
            case 'file':
                this.flieCheckedData()
                break;
            case 'text':
                this.textButtonClick()
                break;
            case 'cancel':
                this.cancelButtonClick(btncode)
                break;
            case 'refresh':
                this.refreshButtonClick()
                break;
            case 'query': 
                this.listQuery();
                break;
            default:
                break;
        }
    }

    render() {
        const { search } = this.props;
        const { NCCreateSearch } = search;
        const {orgVal, agreementType, isEdit, dataList, pageFlag,pageInfo,json, isVisiblePagination, oid, nodeRefs} = this.state;
        return (
            <div className="ProChange-list nc-single-table nc-bill-card">
                <Header {...this.props}
                        ref="header"
                        orgVal={orgVal}
                        json={json}
                        agreementType={agreementType}
                        dataList={dataList}
                        isEdit={isEdit}
                        pageFlag = {pageFlag}
                        deleteAgreementData={this.deleteAgreementData}
                        onBtnClickOperation = {this.onBtnClickOperation.bind(this)}
                        updateState={this.updateState}
                        updateAgreeType={this.updateAgreeType}
                        updateButtonStatus={this.updateButtonStatus}
                        updateOrgValue={this.updateOrgValue}
                        handleCardPagination={this.handleCardPagination.bind(this)}/>
                <div className="entry-staff-query-content" style={{display: pageFlag === "list" ? true : 'none'}}>
                    <MainTable
                        {...this.props}
                        json={json}
                        orgVal={orgVal}
                        agreementType={agreementType}
                        isVisiblePagination={isVisiblePagination}
                        onRowDoubleClick = {this.onRowDoubleClick}
                        paginationEve = {this.paginationEve.bind(this)}
                        pageSizeSelect = {this.pageSizeSelect.bind(this)}
                        pageInfo = {pageInfo}
                    />
                </div>
                <div style={{display: "none"}}>
                    {
                        NCCreateSearch('listquery', {
                            clickSearchBtn: ()=>{ this.searchData() },
                            onlyShowAdvArea: false,
                            showAdvSearchPlanBtn: true,
                            saveSearchPlan: true,
                            oid: oid,
                            onlyShowSuperBtn: true
                        })
                    }
                </div>
                <div className="change-card-from" style={{display: pageFlag === "card" ? true : 'none'}}>
                    <div>
                        <EditForm
                            ref="editForm"
                            {...this.props}
                            orgVal={orgVal}
                            agreementType={agreementType}
                        />
                    </div>
                </div>
                <div>
                    <FileUpload
                        ref = 'FileUpload'
                        json={json}/>
                </div>
                <div>
                    <AddNew
                        ref = "addNew"
                        pkOrg={orgVal.refpk}
                        json={json}
                        pageFlag = {pageFlag}
                        pageInfo = {pageInfo}
                        orgVal={orgVal}
                        agreementType={agreementType}
                        setPageShow = {this.setPageShow}
                        {...this.props}
                        registed = {this.registed}
                        getMainTableData={this.getMainTableData}
                        setMainFormEdit={this.setMainFormEdit.bind(this)}/>
                </div>
                <WpsModal
                    {...this.props}
                    onRef ={ref => nodeRefs.wpsview = ref}
                    appcode={appcode}
                    pk_org={orgVal}
                   />
            </div>

        );
    }
}

const PeriodModel =  handleHash('201908171119', `c=${appcode}&p=${pagecode}`)(createPage({
    // billinfo: [{
    //     billtype: 'extcard', 
    //     pagecode: appcode, 
    //     headcode: 'agreementCard',
    //     bodycode: [
    //         "postcontCardBefore",
    //         "postcontCardAfter",
    //         "secrerycontCardBefore",
    //         "secrerycontCardAfter",
    //         "traincontCardBefore",
    //         "traincontCardAfter",
    //         "hrcm_agreement1CardAfter",
    //         "hrcm_agreement1CardBefore",
    //         "hrcm_agreement2CardAfter", 
    //         "hrcm_agreement2CardBefore"
    //     ]
    // }]
})(ProChange));
ReactDOM.render(<PeriodModel/>, document.querySelector('#app'));
export default ProChange;
